#!/bin/sh

CUR_PATH=$(cd "$(dirname "$0")"; pwd)
source ${CUR_PATH}/../mysql8_server.conf
curr_date=$1
suffix=`date -d "${curr_date}" +%y`
#echo $curr_date
#echo $curr_year
#echo $next_year
#echo $suffix

month_array=('01' '02' '03' '04' '05' '06' '07' '08' '09' '10' '11' '12')
for month in ${month_array[@]}
    do
        datename=${suffix}${month}
        create_table_sql=$(cat <<EOF

        DROP TABLE IF EXISTS vehicle_drivingnumberingrid_${datename};
        CREATE TABLE vehicle_drivingnumberingrid_${datename} (
          id int NOT NULL AUTO_INCREMENT,
          district bigint DEFAULT NULL COMMENT '经纬度对应地区编码',
          name varchar(32) DEFAULT NULL COMMENT '经纬度对应地区名称',
          tile bigint DEFAULT NULL COMMENT '瓦片ID',
          times int DEFAULT NULL COMMENT '经过地区车次',
          month int DEFAULT NULL COMMENT '数据月份',
          detail json DEFAULT NULL COMMENT '位置点明细',
          day varchar(8) DEFAULT NULL COMMENT '数据日期',
          created_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建日期',
          update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
          PRIMARY KEY (id),
          KEY index_bt_tile_month (tile,month)
        ) ENGINE=InnoDB AUTO_INCREMENT=84535 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT COMMENT='瓦片区域车次表'

EOF
)
#echo ${create_table_sql}
mysql -h${HOSTNAME}  -P${PORT}  -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${create_table_sql}"
if [ $? -ne 0 ] ; then
  echo "表创建失败"
else
  echo "表创建成功"
fi
    done

